package com.esteel.settlement.controller;

import java.math.BigDecimal;
import java.util.Date;

//import org.assertj.core.util.DateUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.esteel.settlement.config.pa.PaTemplate;
import com.esteel.settlement.entity.TbSettFund;
import com.esteel.settlement.entity.TbSettFundPK;
import com.esteel.settlement.entity.TbSettInmoney;
import com.esteel.settlement.entity.TbSettOutmoney;
import com.esteel.settlement.entity.TbSettTran;
import com.esteel.settlement.pa.packet.CheckMemberAccountBankBalancePB1020;
import com.esteel.settlement.pa.packet.PaPacket;
import com.esteel.settlement.pa.packet.Query1324Array;
import com.esteel.settlement.pa.packet.Query1325Array;
import com.esteel.settlement.pa.packet.QueryMemberInOutMoneyFlowByTimePB1325;
import com.esteel.settlement.pa.packet.QueryMemberTransactionFlowByTimePB1324;
import com.esteel.settlement.pa.packet.QueryPayInstructionStatusPB1327;
import com.esteel.settlement.pa.packet.RspBP1020;
import com.esteel.settlement.pa.packet.RspBP1324;
import com.esteel.settlement.pa.packet.RspBP1325;
import com.esteel.settlement.pa.packet.RspBP1327;
import com.esteel.settlement.service.SettFundService;
import com.esteel.settlement.service.SettInmoneyService;
import com.esteel.settlement.service.SettOutmoneyService;
import com.esteel.settlement.service.SettTranService;

/**
 * 接收b2bic返回数据的程序
 * @author yuhui
 *
 */
@Controller
public class InMoneyBlanceController {

	
	@Autowired
	private PaTemplate paTemplate;
	
	@Autowired
	private SettFundService settFundService;
	
	@Autowired
	private SettTranService settTranService;
	
	@Autowired
	private SettOutmoneyService settOutmoneyService;
	
	@Autowired
	private SettInmoneyService settInmoneyService;
	
	@RequestMapping("/qInmoneyBlance")
	@ResponseBody
	public String qInmoneyBlance(CheckMemberAccountBankBalancePB1020 bp10201) {
		CheckMemberAccountBankBalancePB1020 bp1020 = new CheckMemberAccountBankBalancePB1020();
		bp1020.setSupAcctId("11006284091401");
		bp1020.setCustAcctId("888800117401651");
		bp1020.setThirdCustId("diangang05");
		bp1020.setCustName("平安测试六零零零六四二零九一八三");
		bp1020.setAcctNo("11014839149004");
		bp1020.setReserve("");
		bp1020.setTranFunc("1021");
		bp1020.setCounterId("69530");
		bp1020.setThirdLogNo("o"+new Date().getTime());
		bp1020.setQydm("9012");
		bp1020.setTransDate(new Date());
		bp1020.setServType(PaPacket.REQUEST);
		RspBP1020 rsp = (RspBP1020) paTemplate.execute(bp1020, RspBP1020.class);
		TbSettFund fund= new TbSettFund();
		TbSettFundPK fundpk= new TbSettFundPK();
		fundpk.setCustAcctId("888800117401651");
		fundpk.setThirdCustId("diangang05");
		fund.setSupAcctId("11006284091401");
		fund.setId(fundpk);
//		fund.setCustType(BigDecimal.valueOf(1l));
//		fund.setCustStatus(BigDecimal.valueOf(1l));
//		fund.setInitTotalAmount(BigDecimal.valueOf(1l));
//		fund.setInitTotalBalance(BigDecimal.valueOf(1l));
//		fund.setInitTotalFreezeAmount(BigDecimal.valueOf(1l));
//		fund.setTotalAmount(BigDecimal.valueOf(1l));
//		fund.setTotalBalance(BigDecimal.valueOf(1l));
//		fund.setTotalFreezeAmount(BigDecimal.valueOf(1l));
//		fund.setTranDate(new Date());
//		fund.setSettDate(new Date());
		settFundService.save(fund);
		return rsp.marshal();
 
	}
	
	@RequestMapping("/qMemberTransactionFlow")
	@ResponseBody
	public String qMemberTransactionFlow(QueryMemberTransactionFlowByTimePB1324 bp13241) {
		QueryMemberTransactionFlowByTimePB1324 bp1324 = new QueryMemberTransactionFlowByTimePB1324();
		bp1324.setSupAcctId("11006284091401");
		bp1324.setOrigThirdLogNo("2");
//		bp1324.setBeginDate(DateUtil.formatAsDatetime(new Date()).substring(0, 7));
//		bp1324.setEndDate(DateUtil.formatAsDatetime(new Date()).substring(0, 7));
		bp1324.setPageNum(0);
		bp1324.setTranFunc("1021");
		bp1324.setCounterId("69530");
		bp1324.setThirdLogNo("o"+new Date().getTime());
		bp1324.setQydm("9012");
		bp1324.setTransDate(new Date());
		bp1324.setServType(PaPacket.REQUEST);
		bp1324.setReserve("");
		RspBP1324 rsp = (RspBP1324) paTemplate.execute(bp13241, RspBP1324.class);
//		if (rsp!=null&&rsp.getArray()!=null&&rsp.getArray().size()>0){
//			for(Query1324Array r:rsp.getArray()){
//				TbSettTran t = new TbSettTran();
//				BeanUtils.copyProperties(r, t);
//				settTranService.add(t);
//			}
//		
//		}
		return rsp.marshal();

	}
	
	@RequestMapping("/queryMemberInOutMoneyFlow")
	@ResponseBody
	public String queryMemberInOutMoneyFlow(QueryMemberInOutMoneyFlowByTimePB1325 bp13251) {
		QueryMemberInOutMoneyFlowByTimePB1325 bp1325 = new QueryMemberInOutMoneyFlowByTimePB1325();
		bp1325.setSupAcctId("11006284091401");
		bp1325.setOrigThirdLogNo("");
//		bp1325.setBeginDate("");
//		bp1325.setEndDate("");
//		bp1325.setPageNum("0");
		bp1325.setTranFunc("1021");
		bp1325.setCounterId("69530");
		bp1325.setThirdLogNo("o"+new Date().getTime());
		bp1325.setQydm("9012");
		bp1325.setTransDate(new Date());
		bp1325.setServType(PaPacket.REQUEST);
		bp1325.setReserve("");
		RspBP1325 rsp = (RspBP1325) paTemplate.execute(bp13251, RspBP1325.class);
//		if (rsp!=null&&rsp.getArray()!=null&&rsp.getArray().size()>0){
//			for(Query1325Array r:rsp.getArray()){
//				if("1".equals(r.getTranFlag())){
//				TbSettInmoney t = new TbSettInmoney();
//				BeanUtils.copyProperties(r, t);
//				settInmoneyService.add(t);
//				}else{
//					TbSettOutmoney t = new TbSettOutmoney();
//					BeanUtils.copyProperties(r, t);
//					settOutmoneyService.add(t);
//				}
//			}
//		
//		}
		return rsp.marshal();

	}
	
	@RequestMapping("/queryPayInstructionStatus")
	@ResponseBody
	public String queryPayInstructionStatus(QueryPayInstructionStatusPB1327 bp13271) {
		QueryPayInstructionStatusPB1327 bp1327 = new QueryPayInstructionStatusPB1327();
		bp1327.setSupAcctId("11006284091401");
		bp1327.setPaySerialNo("11");
		bp1327.setTranFunc("1021");
		bp1327.setCounterId("69530");
		bp1327.setThirdLogNo("o"+new Date().getTime());
		bp1327.setQydm("9012");
		bp1327.setTransDate(new Date());
		bp1327.setServType(PaPacket.REQUEST);
		bp1327.setReserve("");
		RspBP1327 rsp = (RspBP1327) paTemplate.execute(bp13271, RspBP1327.class);
		return rsp.marshal();

	}
}
